#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int sumIndicesWithKSetBits(vector<int> &nums, int k)
    {
        int ret = 0;
        for (int i = 0; i < nums.size(); ++i)
        {
            int count = 0;
            int e = i;
            while (e)
            {
                if (e & 1 != 0)
                {
                    count++;
                }
                e >>= 1;
            }
            if (count == e)
            ret += nums[i];
        }
        return ret;
    }
};
